package com.bzsg.rightsManagementSystem.config.security_config


import com.bzsg.rightsManagementSystem.util.result.ErrorType
import com.bzsg.rightsManagementSystem.util.result.ResultUtil
import com.bzsg.rightsManagementSystem.write
import org.springframework.security.web.access.AccessDeniedHandler
import org.springframework.stereotype.Component
import java.io.IOException
import javax.servlet.ServletException
import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse

@Component
class CustomizeAccessDeniedHandler : AccessDeniedHandler {
    @Throws(IOException::class, ServletException::class)
    override fun handle(
        httpServletRequest: HttpServletRequest?,
        httpServletResponse: HttpServletResponse,
        accessDeniedException: org.springframework.security.access.AccessDeniedException?
    ) {
        httpServletResponse.status = HttpServletResponse.SC_FORBIDDEN;
        httpServletResponse.contentType = "text/json;charset=utf-8"
        httpServletResponse.write((ResultUtil.error(ErrorType.UserNoPermission)))
    }

}